//
//  SYAMainViewController.m
//  BaiSiBuDeJie
//
//  Created by zengqiang on 16/4/24.
//  Copyright © 2016年 zengqiang. All rights reserved.
//

#import "SYAMainViewController.h"
#import "SYAMeViewController.h"
#import "SYANewViewController.h"
#import "SYAEssenceViewController.h"
#import "SYAPublishViewController.h"
#import "SYAFriendTrendsViewController.h"
@interface SYAMainViewController ()

@end

@implementation SYAMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupAllChildVC];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 添加所有子控制器

- (void)setupAllChildVC

{
    // 精华
    SYAEssenceViewController *essenceVC = [[SYAEssenceViewController alloc] init];
    essenceVC.view.backgroundColor = [UIColor redColor];
    UINavigationController *essenceNav = [[UINavigationController alloc] initWithRootViewController:essenceVC];
    [self setupBtn:essenceNav title:@"精华" imageName:@"tabBar_essence_icon" selectedImageName:@"tabBar_essence_click_icon"];
    [self addChildViewController:essenceNav];
    // 新帖
    SYANewViewController *newVC = [[SYANewViewController alloc] init];
    newVC.view.backgroundColor = [UIColor whiteColor];
    UINavigationController *newNav = [[UINavigationController alloc] initWithRootViewController:newVC];
    [self setupBtn:newVC title:@"新帖" imageName:@"tabBar_new_icon" selectedImageName:@"tabBar_new_click_icon"];
    [self addChildViewController:newNav];
    // 发布
    SYAPublishViewController *publishVC = [[SYAPublishViewController alloc] init];
    [self setupBtn:publishVC title:nil imageName:@"tabBar_publish_icon" selectedImageName:@"tabBar_publish_click_icon"];
    publishVC.view.backgroundColor = [UIColor grayColor];
    [self addChildViewController:publishVC];
    // 关注
    SYAFriendTrendsViewController *friendTrendsVC = [[SYAFriendTrendsViewController alloc] init];
        friendTrendsVC.view.backgroundColor = [UIColor yellowColor];
    UINavigationController *friendTrendsNav = [[UINavigationController alloc] initWithRootViewController:friendTrendsVC];
    [self setupBtn:friendTrendsNav title:@"关注" imageName:@"tabBar_friendTrends_icon" selectedImageName:@"tabBar_friendTrends_click_icon"];
    [self addChildViewController:friendTrendsNav];
    // 我
    SYAMeViewController *meVC = [[SYAMeViewController alloc] init];
     meVC.view.backgroundColor = [UIColor blueColor];
    UINavigationController *meNav = [[UINavigationController alloc] initWithRootViewController:meVC];
    [self setupBtn:meNav title:@"我" imageName:@"tabBar_me_icon" selectedImageName:@"tabBar_me_click_icon"];
    [self addChildViewController:meNav];

}


#pragma mark - 设置button内容
- (void)setupBtn:(UIViewController *) nav title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selimageName
{
    nav.tabBarItem.title = title;
    nav.tabBarItem.image = [UIImage imageNamed:imageName];
    nav.tabBarItem.selectedImage = [UIImage imageNamed:selimageName];
}
#pragma mark - 设置button中文字的属性
+ (void)load

{
// 获取全局的UITabBarItem
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
    NSMutableDictionary *normalAttrTitle = [NSMutableDictionary dictionary];
    normalAttrTitle[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    [item setTitleTextAttributes:normalAttrTitle forState:UIControlStateNormal];
    NSMutableDictionary *selAttriTitle = [NSMutableDictionary dictionary];
    selAttriTitle[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    selAttriTitle[NSForegroundColorAttributeName] = [UIColor blackColor];
    [item setTitleTextAttributes:selAttriTitle forState:UIControlStateSelected];
}
@end
